<template>
   <el-main>
     <el-input v-model="name" placeholder="请输入商品名称" style="width:240px"></el-input>
     <el-button type="primary" @click="requestData()">搜索</el-button>
	 <el-button size="small" type="text" @click="add()">添加</el-button>
     <el-table :data="tableData">
          <el-table-column prop="id" label="编号">
         </el-table-column>
          <el-table-column prop="code" label="商品编号">
        </el-table-column>
        <el-table-column prop="name" label="商品名称">
        </el-table-column>
        <el-table-column prop="model" label="型号">
        </el-table-column>
         <el-table-column prop="unit" label="单位">
        </el-table-column>
        <el-table-column prop="lastPurchasingPrice" label="上次进价">
        </el-table-column>
        
        <el-table-column prop="inventoryQuantity" label="库存数量">
        </el-table-column>

      <el-table-column label="操作">
        <template slot-scope="scope">
          <el-button size="small" type="text" @click="handleDelete(scope.row)">删除</el-button>
          <el-button size="small" type="text" @click="handleUpdate(scope.row)">编辑</el-button>
        </template>
      </el-table-column>

      </el-table>
       <div class="block">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-sizes="pageSizes"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total">
        </el-pagination>
  </div>
    </el-main>
</template>
<script>
export default {
    data(){
        return {
           tableData:[],
           currentPage:1,
           pageSizes:[1, 2, 3, 4,5],
           pageSize:5,
           total:5,
           name:'',
        }
    },mounted(){
      this.requestData();

  },methods:{
     handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
        this.pageSize = val;    
         this.requestData();
      },
      handleCurrentChange(val) {
        console.log(`当前页: ${val}`);
        this.currentPage = val;
        this.requestData();

      },
   requestData(){
      var api = "http://localhost:8089/admin/goods/lists";
      var params = {
        name:this.name,
        pageNum:this.currentPage,
        pageSize:this.pageSize
      }
      this.$http.get(api,{params:params}).then(response=>{
        console.log(response);
        this.tableData = response.body.tableData;
        this.total=response.body.total;
      });
   },handleDelete(row){
             alert("ff");
             console.log(row);
             var formData = new FormData();
             formData.append('id',row.id);
             alert("11111")
             var api="http://localhost:8089/admin/goods/deletea";
             this.$http.post(api,formData).then(function(data){
               if(data.body.code=='10000'){
                   this.requestData();
                   alert(row.id)
               }
             alert(data.body.msg);
        
       })
    },handleUpdate(row){
     alert(row.id);
     this.$router.push({name:'upd',params:{id:row.id}});
    },
	add(){
     this.$router.push({name:'/add'});
    }
  } 
}
</script>

